package com.sc.core.make.file.template;

public class Form {
    public final static String content = """
            <th:block th:fragment="form">
                <script>
                    function <identity>FormEl(){
                        let { ref, reactive } = Vue;
                        const FI = baseForm.item;
                        const defaultV = () => {
                            return <default>
                        };
                        const <identity> = reactive(defaultV());
                        let <identity>Ref;
                        const enumOptions = {};
                        <optionsDef>
                        function optionsAssign(name, data){
                            enumOptions[name] = data;
                        }
                        const <identity>Rule = ref({});
            
                        const el = baseForm.form()
                            .model("<identity>")
                            .ref('<identity>Ref')
                            .rules("<identity>Rule")
                            .addItems(
                                <items>
                            )
                            .getEl(function (formEl, rules) {
                                formEl.style.maxWidth = '1000px';
                                <identity>Rule.value = rules;
                            });
           
                        function submit(){
                            <identity>Ref.validate((valid) => {
                                if (!valid) {
                                    return;
                                }
                                sc.axios.post('/admin-<module>/<identity>/create', <identity>).then((res) => {
                                    if (res.code === 200) {
                                        parent.sc.message.success("操作成功");
                                        sc.closeCurrentPage();
                                    } else {
                                        sc.message.error(res.message);
                                    }
                                });
                            });
                        }

                        function appInit(elId){
                            app.create("#" + elId, {
                                mounted(){
                                    <identity>Ref = this.$refs.<identity>Ref;
                                },
                                setup() {
                                    return {
                                        <identity>,
                                        <options>
                                        <identity>Rule,
                                        submit
                                    }
                                }
                            })
                        }
            
                        function initData(data = null){
                            if (data === null){
                                this.initData(defaultV());
                                return;
                            }
                            if (typeof data === 'object'){
                                sc.copyObjValue(data, <identity>);
                                return;
                            }
                            sc.axios.get('/admin-<module>/<identity>/get-info', {id: data}).then((res) => {
                                initData(res.data);
                            });
                        }
            
            
                        return {
                            formEl: (() => {
                                const formEl = document.createElement('el-config-provider');
                                formEl.appendChild(el);
                                formEl.setAttribute(':z-index', 22222222)
                                return formEl;
                            })(),
                            appInit,
                            initData,
                            optionsAssign,
                        }
                    }
                </script>
            </th:block>
            """;
}
